<!--
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<div class="transaction-modal">
    <div class="modal-header">
        <h1>Submit Transaction</h1>
        <button class="icon modal-exit" (click)="activeModal.dismiss()">
            <svg class="ibm-icon" aria-hidden="true">
                <use xlink:href="#icon-close_new"></use>
            </svg>
        </button>
    </div>
    <section class="modal-body">
        <div class="transaction-select">
            <div class="transaction-select-item">
                <p>Transaction Type</p>
            </div>
            <div class="transaction-select-item">
                <div ngbDropdown class="d-inline-block">
                    <button type="button" class="action" id="dropdownMenu1" ngbDropdownToggle><span
                        title="{{selectedTransactionName}}">{{selectedTransactionName}}</span></button>
                    <div class="dropdown-menu" aria-labelledby="dropdownMenu1">
                        <button class="dropdown-item action " *ngFor="let transaction of transactionTypes"
                                (click)="onTransactionSelect(transaction)">{{transaction.getName()}}
                        </button>
                    </div>
                </div>
            </div>
        </div>
        <section class="resource-container">
            <section class="resource-component">
                <div>
                    <p class="resource-preview-text">JSON Data Preview</p>
                </div>
                <div class="scrollbar-padding">
                    <codemirror name="codeMirror" [(ngModel)]="resourceDefinition" [config]="codeConfig"
                                (ngModelChange)="onDefinitionChanged()"
                                width="100%" height="100%" ngDefaultControl>
                    </codemirror>
                </div>
                <div class="optional">
                    <input type="checkbox" name="include-optional" id="include-optional"
                           [(ngModel)]="includeOptionalFields" (change)="generateTransactionDeclaration(false)"  autocomplete="off">
                    <label for="include-optional" class="checkbox-label">Optional Properties</label>
                </div>
                <div class="resource-error-text" ng-if="definitionError!=null">
                    <p>{{definitionError}}</p>
                </div>
            </section>
        </section>
    </section>
    <footer>
        <p class="footer-text">Just need quick test data?
            <button type="button" class="icon" (click)="generateTransactionDeclaration(true)"><u>Generate Random
                Data</u></button>
        </p>
        <div class="transaction-footer-cta">
            <button type="button" class="secondary" (click)="activeModal.dismiss();">
                <span>Cancel</span>
            </button>
            <button name="submitButton" id="submitTransactionButton" type="button" class="primary"
                    (click)="submitTransaction()"
                    [disabled]="definitionError!=null || submitInProgress" ngDefaultControl>
                <div *ngIf="!submitInProgress" ngDefaultControl>
                    <span>Submit</span>
                </div>
                <div *ngIf="submitInProgress" class="ibm-spinner-indeterminate small loop" ngDefaultControl>
                    <div class="loader">
                        <svg class="circular" viewBox="25 25 50 50">
                            <circle class="circle-path" cx="50" cy="50" r="20"/>
                        </svg>
                    </div>
                </div>
            </button>
        </div>
    </footer>
</div>
